package cn.getech.data.development.mapper;

import cn.getech.data.development.dto.TableAndFieldDto;
import cn.getech.data.development.entity.TableInfo;
import cn.getech.data.development.model.dto.CountDbAndTableSizeDto;
import cn.getech.data.development.model.dto.ProcDatasDto;
import cn.getech.data.development.model.dto.TableFieldAndTableDto;
import cn.getech.data.development.model.dto.real.RealApproveQueryDTO;
import cn.getech.data.development.model.dto.real.RealApproveReturnDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 表信息 Mapper 接口
 * </p>
 *
 * @author zenith
 * @since 2018-09-18
 */
@Mapper
public interface TableInfoMapper extends BaseMapper<TableInfo> {

    IPage<TableInfo> selectApplyListPage(Page<TableInfo> page, @Param("params") Map<String, Object> params);

    IPage<TableInfo> selectListOwnPage(Page<TableInfo> page, @Param("params") Map<String, Object> params);

    IPage<TableInfo> selectListPage(Page<TableInfo> page, @Param("params") Map<String, Object> params);

    List<TableInfo> selectListPage(@Param("params") Map<String, Object> params);

    List<TableInfo> listTableByStorageEngine(@Param("params") Map<String, Object> params);

    IPage<TableInfo> listNoRelation(Page<TableInfo> page, @Param("params") Map<String, Object> params);

    IPage<TableInfo> listNoRelationByTenant(Page<TableInfo> page, @Param("params") Map<String, Object> params);

    IPage<TableInfo> usertableListNoRelation(Page<TableInfo> page, @Param("params") Map<String, Object> params);
    @MapKey("userId")
    List<Map<String,Object>>userList(@Param("params") Map<String, Object> params);

    List<TableInfo> selectListByProeIdAndTableId(@Param("procId") Integer procId, @Param("tableId") Integer tableId);

    List<Integer> getTableIdsByNames(@Param("tableNames") List<String> tableNames, @Param("dbName") String dbName);

    List<TableInfo> selectByIds(@Param("tableIdSet") Set<Integer> tableIdSet);

    List<CountDbAndTableSizeDto> countTableRowsAndSizeGroupByDb(@Param("procId") Integer procId);


    TableAndFieldDto getTableByIdToTable(@Param("tableId") Integer tableId);

    List<TableFieldAndTableDto> seleAllTableInfoMaskOpen();

    List<TableFieldAndTableDto> seleAllTableInfoMaskOpenByTableIds(@Param("tableIds") List<Integer> tableIds);

    List<TableInfo> selectListByDbNameAndTableName(@Param("searchDbName") String olderDbName, @Param("searchDbNameSet") Set<String> tableNameSet);

    List<TableInfo> selectTableByProc(@Param("params") Map<String, Object> params);

    List<TableInfo> selectUserProcTables(@Param("dbName") String dbName, @Param("user_id") Integer userId, @Param("tableId") Integer tableId);

    List<TableInfo> selectUserNotProcTables(@Param("dbName") String dbName, @Param("user_id") Integer userId, @Param("tableId") Integer tableId);

    List<TableInfo> selectExitPartitionFieldTables();

    TableInfo getTableById(@Param("id") Integer id);

    List<TableInfo> selectListByDbNamesAndTableNames(@Param("params") Map<String, Object> params);

    void insertAndId(@Param("tableInfo") TableInfo tableInfo);

    TableInfo selectTableByName(@Param("dbName") String dbName, @Param("tableName") String tableName);

    List<TableInfo> getTableProjectNamesByTableId(@Param("ids") List<Integer> ids);

    List<Integer> selectTableIds(@Param("category_id") Integer category_id);

    List<Integer> selectTableInfoIds(@Param("id") Integer id);

    List<TableInfo> listRelation(@Param("params") Map<String, Object> params);

    IPage<RealApproveReturnDTO> realApproveList(IPage<RealApproveReturnDTO> page, @Param("realApproveQueryDTO") RealApproveQueryDTO realApproveQueryDTO, @Param("params") Map<String, Object> params);

    IPage<RealApproveReturnDTO> realList(IPage<RealApproveReturnDTO> page, @Param("params") Map<String, Object> params, @Param("realApproveQueryDTO") RealApproveQueryDTO realApproveQueryDTO);

    List<TableInfo> getRealProjectByTableIds(@Param("ids") List<Integer> tableIds);

    List<Long> selectTableIdByTableName(String tableName);

    Integer selectQualityInfo(@Param("dbName") String dbName,@Param("tableName") String tableName);

    void delQualitySubscribeObject(Integer qualityInfoId);

    void delQualitySubscribeInfo(Integer qualityInfoId);

    void delQualityRuleDaily(Integer qualityInfoId);

    void delQualityRule(Integer qualityInfoId);

    void delQualityInfo(Integer qualityInfoId);

    void delQualityExcelDaily(Integer qualityInfoId);

    void delQualityDaily(Integer qualityInfoId);

    void delMonitorRuleHistory(Integer qualityInfoId);

    void delMonitorRule(Integer qualityInfoId);

    void delMonitorInfo(Integer qualityInfoId);

    List<TableInfo> selectLAllSizeList(@Param("tenantId") Integer tenantId);

    @MapKey("id")
    List<Map<String, Object>> searchProjectList( @Param("params")  Map<String, Object> params);

    List<ProcDatasDto> listProcTables();

    Integer setCollectionTableId(@Param("tableId")Integer tableId,@Param("collectionTableId")Integer collectionTableId);

    Integer deleteCategory(@Param("tableId")Integer tableId);

    Integer insertRelation(@Param("param")  Map<String, Object> param);

    List<String> selectCategoryIdsByTableId(@Param("tableId")Integer tableId);

}
